const app = getApp()
import { requestApi } from '../../../api'
import { formatImage } from '../../../utils/formatImage'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    seller_uid: '',
    type: '',
    code: '',
    certificatesInfo: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      seller_uid: options.seller_uid,
      type: options.type,
      code: options.code
    })

    // 请求验证码
    this.getCertificatesInfo()
  },

  getCertificatesInfo: function () {
    let diu = wx.getStorageSync('diu')
    let param = {
      diu: diu,
      type: this.data.type,
      vcode: this.data.code,
    }

    if (this.data.type == 1) {
      param.seller_uid = this.data.seller_uid
    }

    app.request({
      url: requestApi.getCertificatesInfoUrl,
      login: false,
      data: param,
    }, (data) => {
      if (data.original.data.img && data.original.data.img.length) {
        for (let i = 0, tLen = data.original.data.img.length; i < tLen; i++) {
          data.original.data.img[i].path_full = formatImage.cdnImage(data.original.data.img[i].path, formatImage.THUMBNAIL_L)
        }
      }

      this.setData({
        certificatesInfo: data.original.data
      })
    }, (error) => {
      wx.showModal({
        title: '提示',
        showCancel: false,
        content: error,
      })
    }, () => {
      this.setData({
        topicRequestFlag: false,
      })
    })
  },
})